package com.example.webviewmodule.view

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.webkit.WebView
import com.example.webviewmodule.BaseWebGLRenderer

class GLWebView(context: Context, attrs:AttributeSet?=null,defStyle:Int=0):WebView(context,attrs,defStyle){

    lateinit var mBaseWebGLRenderer:BaseWebGLRenderer



    override fun draw(canvas: Canvas) {
        val glAttachedCanvas=mBaseWebGLRenderer.onDrawViewBegin()
        glAttachedCanvas?.let {
            val xScale=glAttachedCanvas.width/canvas.width.toFloat()
            glAttachedCanvas.scale(xScale,xScale)
            glAttachedCanvas.translate(-scrollX.toFloat(),-scrollY.toFloat())
            super.draw(glAttachedCanvas)
        }
        mBaseWebGLRenderer.onDrawViewEnd()
    }
}